package com.zh.mp.demo.modules.demo.repository;

import com.zh.mp.demo.modules.demo.entity.TUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface UserRepository extends JpaRepository<TUser,Integer> {
    TUser findTUserById(Integer id);

    List<TUser> findUsersByUserName(String userName);

    @Query("select a from TUser a ")
    List<TUser> QueryUserAll();

    @Transactional
    @Modifying
    @Query("update TUser a set a.note=?1 where a.id=?2")
    void updateUser(String note, Integer id);


    List<TUser> userName(String userName);

    @Query("select a from  TUser a  where a.note =?1 and a.sex=?2")
    List<TUser> QueryUserByNote(String note, Integer sex);

    @Query("select a from  TUser a  where a.userName=?1")
    List<TUser> QueryUserByUserName(String userName);
}
